//go:build !scanner

package detector_test

import (
	"reflect"
	"testing"

	"github.com/future-architect/vuls/detector"
	"github.com/future-architect/vuls/models"
	exploitmodels "github.com/vulsio/go-exploitdb/models"
)

func TestConvertToModelsExploit(t *testing.T) {
	tests := []struct {
		name string
		es   []exploitmodels.Exploit
		want []models.Exploit
	}{
		{
			name: "happy",
			es: []exploitmodels.Exploit{
				{
					ExploitType:     exploitmodels.OffensiveSecurityType,
					ExploitUniqueID: "00001",
					URL:             "https://www.exploit-db.com/exploits/00001",
					Description:     "This is a test exploit",
					CveID:           "CVE-2025-0001",
					OffensiveSecurity: &exploitmodels.OffensiveSecurity{
						Document: &exploitmodels.Document{
							Base: exploitmodels.Base{
								FileURL:  "https://gitlab.com/exploit-database/exploitdb/-/blob/main/exploits/00001.txt",
								Verified: false,
							},
						},
					},
				},
				{
					ExploitType:     exploitmodels.OffensiveSecurityType,
					ExploitUniqueID: "00002",
					URL:             "https://www.exploit-db.com/exploits/00002",
					Description:     "This is a test exploit",
					CveID:           "CVE-2025-0001",
					OffensiveSecurity: &exploitmodels.OffensiveSecurity{
						ShellCode: &exploitmodels.ShellCode{
							Base: exploitmodels.Base{
								FileURL:  "https://gitlab.com/exploit-database/exploitdb/-/blob/main/exploits/00002.c",
								Verified: true,
							},
						},
					},
				},
				{
					ExploitType:     exploitmodels.GitHubRepositoryType,
					ExploitUniqueID: "GitHub-f61ce4e51784521b6ee584d42f2aads2",
					URL:             "https://github.com/vuls/CVE-2025-0001",
					Description:     "This is a test exploit",
					CveID:           "CVE-2025-0001",
					GitHubRepository: &exploitmodels.GitHubRepository{
						Star: 12,
						Fork: 3,
					},
				},
			},
			want: []models.Exploit{
				{
					ExploitType: exploitmodels.OffensiveSecurityType,
					ID:          "00001",
					URL:         "https://www.exploit-db.com/exploits/00001",
					Description: "This is a test exploit",
					Verified:    func() *bool { v := false; return &v }(),
					DocumentURL: func() *string {
						s := "https://gitlab.com/exploit-database/exploitdb/-/blob/main/exploits/00001.txt"
						return &s
					}(),
				},
				{
					ExploitType: exploitmodels.OffensiveSecurityType,
					ID:          "00002",
					URL:         "https://www.exploit-db.com/exploits/00002",
					Description: "This is a test exploit",
					Verified:    func() *bool { v := true; return &v }(),
					ShellCodeURL: func() *string {
						s := "https://gitlab.com/exploit-database/exploitdb/-/blob/main/exploits/00002.c"
						return &s
					}(),
				},
				{
					ExploitType: exploitmodels.GitHubRepositoryType,
					ID:          "GitHub-f61ce4e51784521b6ee584d42f2aads2",
					URL:         "https://github.com/vuls/CVE-2025-0001",
					Description: "This is a test exploit",
				},
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			if got := detector.ConvertToModelsExploit(tt.es); !reflect.DeepEqual(got, tt.want) {
				t.Errorf("ConvertToModelsExploit() = %v, want %v", got, tt.want)
			}
		})
	}
}
